package code1_100.code1_10;

import java.util.ArrayList;
import java.util.List;

public class Code6 {
    static class Solution {
        public String convert(String s, int numRows) {
            if (numRows==1)
                return s;
            List<StringBuilder> list = new ArrayList<>();
            boolean tag=false;

            for (int i = 0; i < Math.min(numRows,s.length()); i++) {
                list.add(new StringBuilder());
            }
            int index=0;
            for (char ch:s.toCharArray()) {
                if(index==0||index==numRows-1) tag=!tag;
                list.get(index).append(ch);
                index += tag?1:-1;
            }
            StringBuilder str = new StringBuilder();
            for (StringBuilder sss : list){
                str.append(sss);
            }
            return str.toString();
        }
    }

    public static void main(String[] args) {
        System.out.println(new Code6.Solution().convert("PAYPALISHIRING",4));

    }
}
